﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NetDon.OA.Business;
using NetDon.OA.Data.Linq;
using NetDon.Utilities;

namespace NetDon.OA.Portal.Controls
{
    public partial class UserSelector : System.Web.UI.UserControl
    {
        private string _users;
        public string Users
        {
            get
            {
                if (ViewState["Users"] != null) return (string)ViewState["Users"];
                return _users;
            }

            set { ViewState["Users"] = value; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //imageSelector.OnClientClick =
                //       "window.location='{0}';return false;".Formato(ResolveUrl(SiteUrls.OfficeWork.MeetingAdd) +
                //                                                     "?MeetingId=" + meetingId);
            }
        }

        protected void imgSelector_Click(object sender, ImageClickEventArgs e)
        {

        }

        protected void btnReload_Click(object sender, EventArgs e)
        {

        }

        protected string GetUsers(string userIds)
        {
            var users = userIds.Split(',');
            var userNames = string.Empty;
            var meta = new LinqMetaData();
            foreach (var userId in users)
            {
                var id = userId;
                var query = from user in meta.User
                            where user.UserId == id.ToGuid()
                            select user.UserName;

                var list = query.ToList();
                if (list.Count > 0)
                {
                    userNames += list[0] + ",";
                }
            }
            return userNames.Trim(',');
        }
    }
}